import {request, writeLog} from "@/libs/core.js"
import { Message } from 'element-ui'
/**
会员登录校验逻辑
@param args{account:xxx. loginpw:xxx, vcode:xxxx}
****************************************************************/
const getServerList = async(args) => {
  const data = await request({url:'/project/listServer', data:args, method:'post'});
  if (data && data.code == 0 ) {
    return data;
  }
  return false
}

const doSaveServer = async(args) => {
	const data = await request({url:'/project/saveServer', data:args, method:'post'});
	if (data && data.code == 0) {
		if (!args.id) {
			Message({message: '服务器信息添加成功', type: 'success', duration: 3 * 1000});
		} else {
			Message({message: '服务器信息编辑成功', type: 'success', duration: 3 * 1000});
		}
		return true;
	}
  return false;
}

const doDeleteServer = async(args) => {
  const data = await request({url:'/project/delServer', data:args, method:'post'});
  if(data && data.code == 0){
    Message({message: '服务器信息删除成功', type: 'success', duration: 3 * 1000});
    return true;
  }
  return false;
}

const doDeleteProject = async(args) => {
  const data = await request({url:'/project/delProject', data:args, method:'post'});
  if(data && data.code == 0){
    Message({message: '项目信息删除成功', type: 'success', duration: 3 * 1000});
    return true;
  }
  return false;
}

const getProjectList = async(args) => {
  const data = await request({url:'/project/listProject', data:args, method:'post'});
  if (data && data.code == 0 ) {
    return data;
  }
  return false
}

const doSaveProject = async(args) => {
  const data = await request({url:'/project/saveProject', data:args, method:'post'});
  if (data && data.code == 0) {
    if (!args.id) {
      Message({message: '项目信息添加成功', type: 'success', duration: 3 * 1000});
    } else {
      Message({message: '项目信息编辑成功', type: 'success', duration: 3 * 1000});
    }
    return true;
  }
  return false;
}

const getOfficerList = async(args) => {
  const data = await request({url:'/project/listOfficer', data:args, method:'post'});
  if (data && data.code == 0 ) {
    return data;
  }
  return false
}

const doSaveOfficer = async(args) => {
  const data = await request({url:'/project/saveOfficer', data:args, method:'post'});
  if (data && data.code == 0) {
    if (!args.id) {
      Message({message: '项目成员信息添加成功', type: 'success', duration: 3 * 1000});
    } else {
      Message({message: '项目成员信息编辑成功', type: 'success', duration: 3 * 1000});
    }
    return true;
  }
  return false;
}

const doDeleteOfficer = async(args) => {
  const data = await request({url:'/project/delOfficer', data:args, method:'post'});
  if(data && data.code == 0){
    Message({message: '项目成员信息删除成功', type: 'success', duration: 3 * 1000});
    return true;
  }
  return false;
}

const doPull = async(args) => {
	const data = await request({url:'/project/dopull', data:args, method:'post'});
  if (data && data.code == 0 ) {
    Message({message: '代码拉取成功...', type: 'success', duration: 3 * 1000});
  }
  return data;
}

const doPubQA = async(args) => {
  const data = await request({url:'/project/dopubqa', data:args, method:'post'});
  if (data && data.code == 0 ) {
    Message({message: '代码发布到QA环境成功...', type: 'success', duration: 3 * 1000});
  }
  return data;
}

const doPubSM = async(args) => {
  const data = await request({url:'/project/dopubsm', data:args, method:'post'});
  if (data && data.code == 0 ) {
    Message({message: '代码发布到仿真环境成功...', type: 'success', duration: 3 * 1000});
  }
  return data;
}

const doPubRL = async(args) => {
  const data = await request({url:'/project/dopubrl', data:args, method:'post'});
  if (data && data.code == 0 ) {
    Message({message: '代码发布到正式环境成功...', type: 'success', duration: 3 * 1000});
  }
  return data;
}

const doCodeDiff = async(args) => {
  const data = await request({url:'/project/docodediff', data:args, method:'post'});
  if (data && data.code == 0 ) {
    Message({message: '代码预发布对比成功...', type: 'success', duration: 3 * 1000});
  }
  return data;
}

const loadConfig = async(args) => {
  const data = await request({url:'/project/config', data:args, method:'post'});
  if (data && data.code == 0 ) {
    return data.config;
  }
  return false;
}

export default {
	getServerList,doSaveServer,doDeleteServer,getProjectList,doSaveProject, doDeleteProject,
  getOfficerList,doSaveOfficer,doDeleteOfficer,doPull,doPubQA,doPubSM,doPubRL,doCodeDiff,loadConfig
};